#iChannel0 "./image-1.png"
#iChannel1 "./apex.jpg"
#iChannel2 "./image-2.png"

#define MAIN_IMG_TO_USE iChannel1
float r = 0.88;
float strength = 0.55;
vec4 bulge_original( vec2 img_uv ) {
    // 膨胀
    vec2 bulge_uv = img_uv - .5;
    float d = length( bulge_uv );

    // 扭曲半径 r
    d = d / r;
    // 扭曲强度 strength
    d = pow( d, strength );

    bulge_uv = (bulge_uv) * d;
    bulge_uv += .5;

    // 像素风格化
    vec2 size = vec2( 100, 100 );       // size 越小 像素化程度越高 -> 因为越大采样的越细 0.0~1.0 之间100次采样和10次采样的区别
    bulge_uv = floor( bulge_uv*size ) / size;

    return texture( MAIN_IMG_TO_USE, bulge_uv );;
}

/* --------------------------------------------------------- */
void main() { 
    vec2 imgUV = gl_FragCoord.xy/iResolution.xy;
    vec2 uv = ( gl_FragCoord.xy - iResolution.xy*0.5 ) / iResolution.xx;

    vec4 imgColor = texture( MAIN_IMG_TO_USE, imgUV );

    // 染色
    vec4 color = vec4( 0.7, 0.1, 0.2, 1.0);
    // gl_FragColor = vec4( vec3(color.rgb * imgColor.rgb), 1.0);

    // 颜色通道偏移
    vec2 r_img_uv = imgUV + 0.03;
    vec2 g_img_uv = imgUV - 0.03;
    vec4 r_img = texture( MAIN_IMG_TO_USE, r_img_uv );
    vec4 g_img = texture( MAIN_IMG_TO_USE, g_img_uv );
    vec4 b_img = texture( MAIN_IMG_TO_USE, imgUV );
    // gl_FragColor = vec4( r_img.r, g_img.g, b_img.b, imgColor.a );

    // 膨胀
    color = bulge_original( imgUV );
    

    gl_FragColor = color;

    return;
}